package com.mindata.blockmanager.manager;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.mindata.blockmanager.bean.PermissionData;
import com.mindata.blockmanager.model.Permission;
import com.mindata.blockmanager.repository.PermissionRepository;

/**
 * @author wuweifeng wrote on 2018/4/10.
 */
@Service
public class PermissionManager {
	@Resource
	private PermissionRepository permissionRepository;
	@Resource
	private MemberManager memberManager;

	/**
	 * 查询某个联盟内的所有权限
	 *
	 * @param memberName
	 *            memberName
	 * @return PermissionData
	 */
	public PermissionData findGroupPermission(final String memberName) {
		final PermissionData permissionData = new PermissionData();
		final String groupId = memberManager.findGroupId(memberName);
		permissionData.setPermissions(findPermission(groupId));
		permissionData.setCode(0);
		return permissionData;
	}

	private List<Permission> findPermission(final String groupId) {
		return permissionRepository.findByGroupId(groupId);
	}
}
